class RandomizedSet {
private:
    unordered_map<int, int> valToIndex;
    vector<int> nums;
public:
    RandomizedSet() {
        srand(time(nullptr));
    }
    
    bool insert(int val) {
        if(valToIndex.count(val)) return false;

        nums.push_back(val);
        valToIndex[val] = nums.size()-1;

        return true;
    }
    
    bool remove(int val) {
        if(!valToIndex.count(val)) return false;

        int index = valToIndex[val];
        nums[index] = nums.back();
        nums.pop_back();
        valToIndex[nums[index]] = index;
        valToIndex.erase(val);

        return true;
    }
    
    int getRandom() {
        int index = rand() % nums.size();
        return nums[index];
    }
};

/**
 * Your RandomizedSet object will be instantiated and called as such:
 * RandomizedSet* obj = new RandomizedSet();
 * bool param_1 = obj->insert(val);
 * bool param_2 = obj->remove(val);
 * int param_3 = obj->getRandom();
 */

 class Solution {
public:
    vector<int> productExceptSelf(vector<int>& nums) {
        vector<int> result;
        vector<int> prefixs(nums.size(), 1);
        vector<int> suffixs(nums.size(), 1);

        prefixs[0] = nums[0];
        for(int i = 1; i < nums.size(); ++i)
        {
            prefixs[i] = nums[i] * prefixs[i-1];
        }

        suffixs[suffixs.size()-1] = nums[nums.size()-1];
        for(int i = nums.size()-2; i >= 0; i--)
        {
            suffixs[i] = nums[i] * suffixs[i+1];
        }

        for(int i  = 0; i < nums.size(); ++i)
        {
            int prefixVal = 0;
            int suffixVal = 0;

            prefixVal = (i > 0) ? prefixs[i-1] : 1;
            suffixVal = (i < nums.size()-1) ? suffixs[i+1] : 1;

            result.push_back(prefixVal * suffixVal);
        }

        return result;
    }
};